package com.sample.springbatch.job.sample.writer;

import com.sample.springbatch.model.User;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

/**
 * JdbcBatchItemWriter实现类
 * Created by zwg on 2017/8/8.
 */
@Component
public class RepayOrderJdbcBatchItemWriter<RepayOrderInfo> extends JdbcBatchItemWriter {

    @Autowired
    public DataSource dataSource;

    public RepayOrderJdbcBatchItemWriter() {
        setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<User>());
        setSql("INSERT INTO repay_order_info (user_id,product_id,contract_no,amount,repay_type,repay_method,buss_date) VALUES (:userId,:productId,:contractNo,:amount,:repayType,:repayMethod,:bussDate)");
        //构造函数里不支持 @Autowired 的实例
        //setDataSource(dataSource);
    }

    @PostConstruct
    public void init(){
        setDataSource(dataSource);
    }


}
